package com.GUI.lesson1;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class jiangting3 {
    public static void main(String[] args) {
        //启动
       new MyFrame1();
    }
}

class MyFrame1 extends Frame{
    public MyFrame1(){
        TextField textField = new TextField();
        add(textField);

        //监听这个文本框输入的文字
        MyActionListener2 myActionListener2 = new MyActionListener2();
        //按下enter就会触发这个输入框的事件
        textField.addActionListener(myActionListener2);

        //设置替换编码
        textField.setEchoChar('*');
        setVisible(true);
        pack();

    }
}

class MyActionListener2 implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        TextField field = (TextField) e.getSource(); //获得一些资源返回一个对象
        System.out.println(field.getText());//获得文本框的文本
        field.setText(" ");
    }
}